import axios from "axios";

import { useUserMsg } from '../stores/user';
const userMsg = useUserMsg()

const myAxios = axios.create({
  baseURL: "http://47.93.246.252:7001",
  timeout: 100000,
  headers: {
    'content-type': 'application/x-www-form-urlencoded',
    // authorization: token
  }
});

// 添加请求拦截器
myAxios.interceptors.request.use(function (config) {

  // 根据状态管理器中的用户状态，获取token
  config.headers.authorization = userMsg.msg.token;

  config.method==="get" ? config.params.isdev = "qf" : config.data.isdev = "qf";

  return config;
}, function (error) {
  return Promise.reject(error);
});

// 添加响应拦截器
myAxios.interceptors.response.use(function (response) {
  return response;
}, function (error) {
  return Promise.reject(error);
});

export default myAxios;
